// ---------------------------------------------------------------------
//
// -- 世界排行列表item
// -- author £
//
// ---------------------------------------------------------------------

cc.Class({
    extends: cc.Component,

    properties: {
        lbScore: cc.Label,
        lbName: cc.Label,
        head: cc.Sprite,
        numRank: require('BaseNum'),
        defaultHead: cc.SpriteFrame,
    },

    ctor: function () {
        // this._headT = new cc.Texture2D();
    },

    // use this for initialization
    onLoad: function () {
        
    }, 

    start: function () {
    },

    setData: function (data) {
        if (!data) return; 

        let rank = data.rank;

        this.reset();

        if (rank === 1) 
            rank = 'a';
        else if (rank === 2)
            rank = 'b';
        else if (rank === 3)
            rank = 'c';

        this.numRank.updateNum(rank);
        this.lbName.string = data.nick_name;
        this.lbScore.string = data.best_score !== undefined ? data.best_score :
            data.today_best_score;
        require('Platform').setHead(data.avatar, data.user_id, this.head);
    },

    reset: function () {
        this.numRank.clear();
        this.lbName.string = '';
        this.lbScore.string = '';
        this.head.spriteFrame = this.defaultHead;
    },

    // called every frame, uncomment this function to activate update callback
    // update: function (dt) {

    // },
});
